<?php
/***********************************************************
 * Copyright (C) 2010-2012 by Lifire
 * All rights reserved.
 * 
 * Filename: 
 * Description: 
 * 
 * Created by Lifire at 2010-11-18
 * Email:yunzhi.li.08@gmail.com
 ***********************************************************
 */
 ?>
<?php

class OrderAction extends Action 
{

	public function index()
	{
		$Order=D("Order");
		$count=$Order->count();
		import("ORG.Util.Page");
		$listRows=500000000;
		$p=new page($count,$listRows);
		$list=$Order->findAll(null,'*','addtime DESC',$p->firstRow.','.$p->listRows);
		$page=$p->show();
		if ($list!==false) 
		{
			$this->assign('page',$page);
			$this->assign('list',$list);
		}
		$this->display();		
	}
	public function add()
	{
		if(!$this->isPost())
		{
			$this->redirect();return;
		}
		else
		{
    		$verify=isset($_POST['verify'])?trim($_POST['verify']):'';
    		if(md5($verify)!=Session::get('verify'))
    		{
    			$this->assign('jumpUrl',__APP__.'/Order');
    			$msg="验证码错误或已经过期";$this->error($msg);return;
    		}					
			
			$name=isset($_POST['name'])?trim($_POST['name']):'';
			$tel=isset($_POST['tel'])?trim($_POST['tel']):'';
			$email=isset($_POST['email'])?trim($_POST['email']):'';
			$gender=isset($_POST['gender'])?trim($_POST['gender']):'0';
			$address=isset($_POST['address'])?trim($_POST['address']):'';
			$area=isset($_POST['area'])?trim($_POST['area']):'';
			$housetype=isset($_POST['housetype'])?trim($_POST['housetype']):'';
			$style=isset($_POST['style'])?trim($_POST['style']):'';
			$price=isset($_POST['price'])?trim($_POST['price']):'';
			$other=isset($_POST['other'])?trim($_POST['other']):'';
		
			if($name=='')
			{
				$msg="请填写姓名";
				$this->error($msg);return;
			}
			if($tel=='')
			{
				$msg="请填写电话号码";
				$this->error($msg);return;
			}
			if($address=='')
			{
				$msg="请填写好地址";
				$this->error($msg);return;
			}		
			
			$data=array(
				'name'=>$name,
				'tel'=>$tel,
				'email'=>$email,
				'gender'=>$gender,
				'address'=>$address,
				'area'=>$area,
				'housetype'=>$housetype,
				'style'=>$style,
				'price'=>$price,
				'other'=>$other,
			);
			$Order=D("Order");
			if(!$Order->create($data))
			{
				$this->error($Order->getError());return;
			}
			if(!$Order->add())
			{
				$msg="在线订单出错！";
				$this->error($msg);return;
			}
			$this->assign('jumpUrl',__URL__);
			$msg="在线订单成功!";
			$this->success($msg);
		}
	}
	public function verify() 
	{
        import("ORG.Util.Image");
       	Image::buildImageVerify(4,1,'png',48,20,'verify');       	    	
	}   	
}
?>